package com.mt.mtyx.sys.controller;

import com.mt.mtyx.common.exception.BusinessException;
import com.mt.mtyx.common.result.Result;
import com.mt.mtyx.entity.sys.Region;
import com.mt.mtyx.sys.service.RegionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author WMT
 * @Date 2023/7/18 13:11
 */
@Api(tags = "区域")
@RequestMapping("/admin/sys/region")
@RestController
public class RegionController {

    @Autowired
    private RegionService regionService;

    @ApiOperation("根据关键字获取区域信息")
    @GetMapping("/findRegionByKeyword/{keyword}")
    public Result<List<Region>> findRegionByKeyword(@PathVariable String keyword) throws Exception {
        if (StringUtils.isEmpty(keyword)) {
            throw new BusinessException("关键词不能为空！", HttpStatus.BAD_REQUEST.value());
        }
        return Result.success(regionService.findRegionByKeyword(keyword));
    }

}
